<?php

class DiaryVideoModel
{
	private $DiaryVideoPreKey = 'DV/';

	public function addDiaryVideo($data){
		if (empty($data['bodyId']) || empty($data['uid'])){
			return false;
		}
		$new = [
			'bodyId' => $data['bodyId'],
			'uid' => $data['uid'],
			'create_at' => AC::SERVER_TIME,
			'operate_at' => AC::SERVER_TIME
		];
		isset($data['rate']) && $new['rate'] = 0;
		$key = $this->DiaryVideoPreKey. $data['bodyId'];
		$result = Storage::addData($key, $new);
		return $result;
	}

	public function deleteDiaryVedioByBodyud($bodyId, $uid) {
		if (empty($bodyId) || empty($uid)){
			return false;
		}

		$key = $this->DiaryVideoPreKey. $bodyId;
		$where = ['bodyId'=>$bodyId, 'uid'=> $uid];
		return Storage::delConditionData($key, $where);
	}

	public function getDiaryVideoInfoByBodyid($bodyId, $uid=0){
		$key = $this->DiaryVideoPreKey. $bodyId;
		$where = 'status=0';
		$uid && $where .= ' AND uid='.$uid;
		$result = Storage::getConditionData($key, $where);
		return $result;
	}

	public function updateDiaryVideoInfo($bodyId, $set){
		$key = $this->DiaryVideoPreKey. $bodyId;
		$where = ['bodyId'=>$bodyId];
		$result = Storage::setConditionData($key, $set, $where);
	}

}